#include "hetman.h"
#include "plansza.h";
#include <cstdlib>
Hetman::Hetman(int x, int y)
    :Figura(x, y, HETMAN)
{
    this->czyAktywna=true;
    this->Graf='H';
}

bool Hetman::czyMogeIsc(int x, int y, Plansza *plansza)
{
    if(this->czyAktywna == false)
      return false;
    if(x != this->x && y != this->y)
    {
       int i=this->x;
       int j=this->y;
        if(x < 1 || x >= 9 || y < 1 || y >= 9)
           return false;

        if(abs(i - x) != abs(j - y)) return false;

        if(x > i)
          x--;
        else
          x++;
        if(y > j )
          y--;
        else
          y++;

        while(x != i && y != j)
        {
            if(plansza->GetFiguraAt(x,y) != NULL)
                return false ;

                if(x > i)
                    x--;
                else
                    x++;
                if(y > j )
                    y--;
                else
                    y++;
        }
            return true;
    }


    ////////////// W DOL //////////////
    else if(this->y == y && this->x < x)
    {
        for ( int i = this->x+1; i != x ; i++)
        {
            if(plansza->GetFiguraAt(i,y) != NULL)
                return false;

        }
        return true ;
    }
    ///////////////// W GORE//////////
    else if(this->y == y && this->x > x)
    {
        for ( int i = this->x-1; i != x ; i--)
        {
            if(plansza->GetFiguraAt(i,y) != NULL)
                return false;

        }
        return true ;
    }
    //////////////// W LEWO /////////////
    else if(this->x == x && this->y > y)
    {
        for ( int i = this->y-1; i != y ; i--)
        {
            if(plansza->GetFiguraAt(x,i) != NULL)
                return false;

        }
        return true ;
    }
    //////////////// W PRAWO ////////////////
    else if(this->x == x && this->y < y)
    {
        for ( int i = this->y+1; i != y ; i++)
        {
            if(plansza->GetFiguraAt(x,i) != NULL)
                return false;

        }
        return true ;
    }
         return false ;
}


bool Hetman::czyMogeBic(int x, int y, Plansza *plansza)
{
    return czyMogeIsc(x,y,plansza);
}
